#include "handlers.hxx"

/*
int action_handler_demo(EPM_action_message_t msg) {
	BEGIN;
	info_syslog("*Function: %s.%s, task: %d, action: %d\n", EX_STRING(SITE), __FUNCTION__, msg.task, msg.action);
	ifail = foreach_task_attachments(msg.task, msg.action, NULL);
	END;
}
*/

/*
EPM_decision_t rule_handler_demo(EPM_rule_message_t msg) {
	EPM_decision_t decision = EPM_go;
	info_syslog("*Function: %s.%s, task: %d, action: %d\n", EX_STRING(SITE), __FUNCTION__, msg.task, msg.proposed_action);
	if (ITK_ok != foreach_task_attachments(msg.task, msg.proposed_action, NULL))
		decision = EPM_nogo;
	return (decision);
}
*/

//TODO: 流程处理(handler)

OUR_action_handler action_handlers[] = {
	//名称，          描述，            函数
	{NULL,            NULL,            NULL}
};

OUR_rule_handler rule_handlers[] = {
	//名称，          描述，            函数
	{NULL,            NULL,            NULL}
};

int OUR_register_handlers(int* decision, va_list args) {
	BEGIN;
	int registered = 0;
	int action_handler_size = sizeof(action_handlers) / sizeof(OUR_action_handler) - 1;
	int rule_handler_size = sizeof(rule_handlers) / sizeof(OUR_rule_handler) - 1;
	for (int i = 0; i < action_handler_size; i++) {
		REGISTER_ACTION_HANDLER(action_handlers[i].name, action_handlers[i].desc, action_handlers[i].func);
		if (ITK_ok == ifail)
			registered++;
	}
	for (int i = 0; i < rule_handler_size; i++) {
		REGISTER_RULE_HANDLER(rule_handlers[i].name, rule_handlers[i].desc, rule_handlers[i].func);
		if (ITK_ok == ifail)
			registered++;
	}
	info_syslog("*There are %d/%d handlers in '%s.%s' registered.\n\n",
		registered, action_handler_size + rule_handler_size, EX_STRING(SITE), __FUNCTION__);
	END;
}
